package com.jie.component.lock.config;

import com.jie.common.util.LogUtil;
import com.jie.component.lock.aspect.ServiceLockAspect;
import com.jie.component.lock.core.ManageLocker;
import com.jie.component.lock.factory.ServiceLockFactory;
import com.jie.component.lock.lockinfo.LockInfoHandle;
import com.jie.component.lock.lockinfo.LockInfoType;
import com.jie.component.lock.lockinfo.factory.LockInfoHandleFactory;
import com.jie.component.lock.lockinfo.impl.ServiceLockInfoHandle;
import com.jie.component.lock.util.ServiceLockTool;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;

public class ServiceLockAutoConfiguration {
    
    @Bean(LockInfoType.SERVICE_LOCK)
    public LockInfoHandle serviceLockInfoHandle() {
        LogUtil.autoConfigLog("LockInfoHandle");
        return new ServiceLockInfoHandle();
    }
    
    @Bean
    public ManageLocker manageLocker(RedissonClient redissonClient) {
        LogUtil.autoConfigLog("ManageLocker");
        return new ManageLocker(redissonClient);
    }
    
    @Bean
    public ServiceLockFactory serviceLockFactory(ManageLocker manageLocker) {
        LogUtil.autoConfigLog("ServiceLockFactory");
        return new ServiceLockFactory(manageLocker);
    }

    @Bean
    public ServiceLockAspect serviceLockAspect(LockInfoHandleFactory lockInfoHandleFactory, ServiceLockFactory serviceLockFactory) {
        LogUtil.autoConfigLog("ServiceLockAspect");
        return new ServiceLockAspect(lockInfoHandleFactory,serviceLockFactory);
    }
    
    @Bean
    public ServiceLockTool serviceLockUtil(LockInfoHandleFactory lockInfoHandleFactory, ServiceLockFactory serviceLockFactory) {
        LogUtil.autoConfigLog("ServiceLockTool");
        return new ServiceLockTool(lockInfoHandleFactory,serviceLockFactory);
    }

    @Bean
    public LockInfoHandleFactory lockInfoHandleFactory() {
        LogUtil.autoConfigLog("LockInfoHandleFactory");
        return new LockInfoHandleFactory();
    }
}
